﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace YunSpace.Web.Areas.OrderFlowManage.Controllers
{

    using YunSpace.Application.OrderFlowManage;
    using YunSpace.Core;
    using YunSpace.Domain.Entity.OrderFlowManage;
    using YunSpace.Domain.ViewModel;

    /// <summary>
    /// 客户订单 - 带看分配
    /// </summary>
    public class TakelookAllotController : ControllerBase
    {
        private ClientOrdertakelookallotApp clientOrdertakelookallotApp = new ClientOrdertakelookallotApp();

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGridJson(Pagination pagination, string keyword)
        {
            var data = new
            {
                rows = clientOrdertakelookallotApp.GetList(pagination, keyword),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        /// <summary>
        /// 获取所有激活的活动
        /// </summary>
        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetActiveOrderInfo() {
            var dept = Configs.GetValue("ClientOrder.Dept").ToObject<SelectListItemViewModel>();

            var data = new {
                Themes = clientOrdertakelookallotApp.GetActiveOrder(),
                Dept = dept,
                Users = clientOrdertakelookallotApp.GetUsersByDeptId(dept.Value)
            };

            return Content(data.ToJson());
        }

        /// <summary>
        /// 提交表单
        /// </summary>
        /// <param name="clientOrdertakelookallotEntity">表单实体</param>
        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitForm(ClientOrdertakelookallotEntity clientOrdertakelookallotEntity, string keyValue)
        {
            var isAdd = clientOrdertakelookallotApp.SubmitForm(clientOrdertakelookallotEntity, keyValue);

            return isAdd ? Success("操作成功。") : Error("此活动主题已添加过相关的场地空间！");
        }


    }
}